{% include "../common/header.html" %}

    <div class="cl pd-5 bg-1 bk-gray mt-20" style="margin-bottom: 15px;">
        <span class="l">
                <a class="btn btn-primary radius" data-title="添加标签" href="/{{action}}/item">
                    <i class="Hui-iconfont"></i> 添加用户
                </a>
                <a href="javascript:;" onclick="delsome()" class="btn btn-danger radius">
                    <i class="Hui-iconfont"></i> 批量删除
                </a>
            </span>
        <span class="r">共有数据：<strong>{{pageData.count}}</strong> 条</span>
    </div>
    <div class="dataTables_wrapper no-footer">
        <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
            <thead>
                <tr class="text-c" role="row">
                    <th width="25" class="sorting_disabled" rowspan="1" colspan="1" aria-label="" style="width: 25px;">
                        <input type="checkbox" name="" value="">
                    </th>
                    <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="descending" aria-label="ID: 升序排列" style="width: 80px;">ID</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">用户名</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">邮箱</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">是否验证</th>
                    <th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">角色</th>
                    <th width="120" class="sorting_disabled" rowspan="1" colspan="1" aria-label="操作" style="width: 120px;">操作</th>
                </tr>
            </thead>
            <tbody>
                {% for item in itemList%}
                <tr class="text-c odd" role="row">
                    <td>
                        {%if item.role!="superadmin" %}
                        <input type="checkbox" value="{{item.uid}}" name="">
                        {%endif%}
                    </td>
                    <td>{{item.uid}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.email}}</td>
                    <td></td>
                    <td>{%if item.rolename%}{{item.rolename}}{%else%}访客{%endif%}</td>
                    <td class="f-14 td-manage">
                        <a style="text-decoration:none" class="ml-5 edit" href="/{{action}}/item/{{item.uid}}" title="编辑">
                            <i class="Hui-iconfont"></i>
                        </a>
                        {%if item.role!="superadmin" %}
                        <a style="text-decoration:none" class="ml-5 delete" del-id="{{item.uid}}" title="删除"><i class="Hui-iconfont"></i></a>
                        {%endif%}
                    </td>
                </tr>
                {%endfor%}
            </tbody>
        </table>
        {% if pageData.count>10 %} {% include "../common/pagination.html" %} {%endif%}
    </div>

{% include "../common/footer.html" %}


<script>
$('.delete').bind('click', function () {
    var delId = $(this).attr("del-id");
    var delids=[];
    delids.push(delId);
    var r = confirm("确定删除？");
    if (r) {
        $.ajax({
            url: '/user/delsome',
            data: {delarr:delids},
            type: 'POST',
            success: function (json) {
                if (json.errno === 0) {
                    alert("删除成功！");
                    window.location.href = "/user";
                }else{
                    alert(json.errmsg)
                }
            }
        })
    } else {
    }
})
//批量删除
var delsome=function(){
    var delids=[];
    $.each($('input[type="checkbox"]','tbody'),function(i,item){
        if($(item).is(':checked')){
            delids.push($(this).val());
        }
    })
    var r = confirm("确定删除？");
    if (r) {
        $.ajax({
            url: '/user/delsome',
            data: {delarr:delids},
            type: 'POST',
            success: function (json) {
                if (json.errno === 0) {
                    alert("删除成功！");
                    window.location.href = "/user";
                }else{
                    alert(json.errmsg)
                }
            }
        })
    } else {
        return false
    }
}
</script>
